//获取应用实例
const app = getApp()

Page({
  data: {
    oldPayPassword: false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: false, //文本框焦点
    firstPayPassword: false,
    secondPayPassword: false,
    newpassword: '',
    agangpassword: ''
  },
  onLoad: function () {
    this.showInputLayer();
  },
  /**
   * 显示支付密码输入层
   * 原始密码
   */
  showInputLayer: function(){
    this.setData({ oldPayPassword: true, payFocus: true });
  },
  showfirst: function(){
    this.setData({
      firstPayPassword: true,
      payFocus: true
    })
  },
  /**
   * 获取焦点
   */
  getFocus: function(){
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   * 老
   */
  inputPwd: function(e){
      this.setData({ pwdVal: e.detail.value });
      if (e.detail.value.length >= 6){
        this.setData({ oldPayPassword: false, payFocus: true, pwdVal: this.data.pwdVal, firstPayPassword: true });
      }
  },
  /**
   * 输入密码监听
   * 新1
   */
  inputPwdNewOne: function(e){
      this.setData({ newpassword: e.detail.value });
      if (e.detail.value.length >= 6){
        this.setData({ firstPayPassword: false, payFocus: true, secondPayPassword: true });
      }
  },
  /**
   * 输入密码监听
   * 新2
   */
  inputPwdNewTwo: function(e){
      this.setData({ agangpassword: e.detail.value });
      if (e.detail.value.length >= 6){
        if (this.data.agangpassword != this.data.newpassword) {
          wx.showToast({
            title: '密码输入不一致',
            icon: 'none'
          })
          setTimeout(function (params) {
            wx.navigateTo({
              url: '../setPassword/setPassword',
            })
          }, 1000)
        }else {
          wx.request({
            url: app.globalData.baseUrl + '/user/updatePaymentCode',
            data: {
              xcxOpenId: app.globalData.xcxOpenId,
              paymentCode: this.data.pwdVal,
              updatePwd: this.data.newpassword
            },
            method:'POST',
            header: {
              'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            success:function(res){
              if (res.code == 0) {
                wx.showToast({
                  title: '修改成功！'
                })
                setTimeout(function (params) {
                  wx.navigateTo({
                    url: '../setPassword/setPassword',
                  })
                }, 1000)
              }else {
                wx.showToast({
                  title: res.data.msg,
                  icon: 'none'
                })
                setTimeout(function (params) {
                  wx.navigateTo({
                    url: '../setPassword/setPassword',
                  })
                }, 1000)
              }
            }
          })
        }
      }
  }
})